<#import "/resource/common_html_front.ftl" as html>
<#import "/indexMenu.ftl" as menu>

<@html.htmlBase title="模拟网关支付">
    <@menu.menu selectMenu=""/>

<h3>待支付信息</h3>
<table class="table">
    <tr>
        <td>订单号:</td>
        <td>${payInfo.WIDout_trade_no!""}</td>
    </tr>
    <tr>
        <td>标题:</td>
        <td>${payInfo.WIDsubject!""}</td>
    </tr>
    <tr>
        <td>金额:</td>
        <td>${payInfo.WIDprice!""}</td>
    </tr>
    <tr>
        <td>配送费:</td>
        <td>${payInfo.logistics_fee!""}</td>
    </tr>
</table>
<div> <input id="btnPay" type="button" class="btn btn-primary" value="支付宝支付"/>
    <input id="wxPay" type="button" class="btn btn-primary" value="微信支付"/>
</div>

<script>
    $(document).ready(function(){
        $("#wxPay").click(function(){
                $.ajax({
                    dataType:"text",
                    url:"${basepath}/paygate/wxPay",
                    type:"POST",
                    data:{
                        orderId:"${payInfo.WIDout_trade_no}",
                        name:"${payInfo.WIDsubject}",
                        money:"${payInfo.WIDprice}",
                        courierMoney:"${payInfo.logistics_fee}"
                    },
                    success:function(data){
                        window.location.href="${basepath}/paygate/towxPay?code=" + data
                                + "&orderId=${payInfo.WIDout_trade_no}"
                                + "&money=${payInfo.WIDprice}"
                                + "&name=${payInfo.WIDsubject}"
                                + "&courierMoney=${payInfo.logistics_fee}";
                    },
                    error:function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("失败，请检查网络后重试");
                    }
                })

        });
    })

    $(function(){
        $("#btnPay").click(function(){
                $.ajax({
                    dataType:"json",
                    url:"${basepath}/paygate/dummyPay",
                    type:"POST",
                    data:{
                        orderId:"${payInfo.WIDout_trade_no}",
                        name:"${payInfo.WIDsubject}",
                        money:"${payInfo.WIDprice}",
                        courierMoney:"${payInfo.logistics_fee}"
                    },
                    success:function(data){
                        window.location.href="${basepath}/paygate/toAliPay?"
                                + "orderId=${payInfo.WIDout_trade_no}"
                                + "&money=${payInfo.WIDprice}"
                                + "&name=${payInfo.WIDsubject}"
                                + "&courierMoney=${payInfo.logistics_fee}";
                    },
                    error:function(data){
                        alert("支付失败");
                    }
                });
        });
    })
</script>
</@html.htmlBase>